package com.zzptc.easyshop.servlet;

import com.zzptc.easyshop.dao.UserDao;
import com.zzptc.easyshop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name = "LoginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        request.setCharacterEncoding("utf8");
        response.setCharacterEncoding("utf8");
        PrintWriter pw = response.getWriter();
        String username = request.getParameter("userName");   // 获取表单的userName的内容
        String pwd = request.getParameter("passWord");
        //打印在网页上
        Users users = new Users();
        users.setEu_user_name(username);
        users.setEu_password(pwd);
        UserDao ud = new UserDao();
        boolean i = false;
        try {
            i = ud.login(users);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (i) {
            pw.print(username + "------登录成功!");
        } else {
            pw.print(username + "------登录失败!");
        }
    }
}
